<template>
  <el-container>
    <el-aside :width="isCollapse ? '60px' : '300px'">
      <div class="logo">
        <h1><img src="../images/logo.png" @click="tohome">Hpx仓库管理系统</h1>
      </div>
      <el-menu active-text-color="#ffd04b" background-color="#663d74" default-active="/workbench" text-color="#c8c6c4"
        :collapse="isCollapse" :collapse-transition="false" router>
        <el-menu-item index="/workbench">
          <el-icon>
            <Monitor />
          </el-icon>
          <span>工作台</span>
        </el-menu-item>
        <el-sub-menu index="2">
          <template #title>
            <el-icon>
              <Menu />
            </el-icon>
            <span>系统管理</span>
          </template>
          <el-menu-item index="/user">
            <el-icon>
              <UserFilled />
            </el-icon>
            <span>用户</span></el-menu-item>
          <el-menu-item index="2">
            <el-icon>
              <Histogram />
            </el-icon>
            <span>产品</span></el-menu-item>
        </el-sub-menu>
        <el-menu-item index="/warehouse">
          <el-icon>
            <Box />
          </el-icon>
          <span>仓库</span>
        </el-menu-item>
      </el-menu>
    </el-aside>
    <el-container>
      <el-header>
        <el-icon @click="isCollapse = !isCollapse">
          <Fold v-if="!isCollapse" />
          <Expand v-else />
        </el-icon>
        <div class="userinfo">
          <el-avatar :size="35" src="https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png"></el-avatar>
          <el-dropdown trigger="click" >
            <span>{{ NickName }}
            </span>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item>账户管理</el-dropdown-item>
                <el-dropdown-item>密码修改</el-dropdown-item>
                <el-dropdown-item divided @click="logout" color="red">退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
      </el-header>
      <el-main>
        <div class="active">
          <RouterView></RouterView>
        </div>
      </el-main>
    </el-container>
  </el-container>
</template>

<script setup>
import { ref,onMounted } from 'vue'
import { useRouter,useRoute } from 'vue-router';
import { RouterView } from 'vue-router';
let isCollapse = ref(false)
let router = useRouter()
let route = useRoute()
let NickName= ref('')
onMounted(()=>{
  NickName=route.query.NickName
})


function tohome() {
  router.push('/workbench')
}
function logout() {
  router.push('/login')
}
</script>

<style scoped>
.el-container {
  height: 100%;
}

.el-aside {
  display: flex;
  flex-direction: column;
  background-color: #663d74;
  color: #ffd04b;
  transition: width 0.7s ease-out;
  overflow: hidden;
}

.el-aside span {
  font-size: 18px;
  font-weight: bolder;
  overflow: hidden;
}

.logo img {
  margin-right: 10px;
  cursor: pointer;
}

.logo h1 {
  display: flex;
  overflow: hidden;
  font-size: 30px;
  height: 60px;
  line-height: 60px
}

.el-menu {
  flex-grow: 1;
  border: 0;
}

.el-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: #663d74;
  font-size: 24px;
}

.el-header .el-icon,
.el-header span {
  cursor: pointer;
  color: white;
}
.el-header .el-icon:hover,
.el-header span:hover {
  cursor: pointer;
  color: #ffd04b;
}

.el-header .userinfo {
  display: flex;
  align-items: center;

}

.userinfo .el-dropdown {
  margin-left: 10px;
  height: 30px;
  line-height: 30px;
  outline: none;
}

.el-main {
  background-color: #2f3542;
}

.el-main .active {
  background-color: #a67eb7;
  padding: 20px;
  border-radius: 5px;
}
</style>